<template>
  <div class="memory-container">
    <p class="title">设备内存占比</p>
    <div class="memory-div clearfix">
      <ul class="left">
        <li class="left-item" v-for="(item, index) in data" :key="index">
          <i :style="{ background: item.color }"></i>
          <span>{{ item.text }}</span>
        </li>
      </ul>
      <div class="right">
        <div
          class="right-item"
          v-for="(item, index) in data"
          :key="index"
          :style="{ height: item.value, backgroundColor: item.color }"
        >
          {{ item.value }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { cpuAndMem } from '@/api/homePage'

export default {
  name: 'MemoryRatio',
  data() {
    return {
      colors: [
        '#005DD7',
        '#188FFF',
        '#59CCFF',
        '#13C1C1',
        '#27A97D',
        '#FACB14',
        '#FF862E'
      ],
      data: []
    }
  },
  mounted() {
    this.doQuery()
  },
  methods: {
    async doQuery() {
      const {
        data: { data }
      } = await cpuAndMem()

      this.data = data.memList.map((item, index) => {
        return {
          text: item.name,
          value: `${item.usedMem}%`,
          color: this.colors[index % 7]
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.memory-container {
  position: absolute;
  width: 320px;
  height: 440px;
  top: 580px;
  left: 1573px;
  background-size: 100%;
  // background: linear-gradient(180deg, rgba(7, 122, 254, 0.23) 0%, rgba(0, 94, 162, 0) 100%);
  background-image: url(../../assets/platform/lowerright.png);

  .title {
    text-align: center;
    color: #00c2ff;
    font-size: 16px;
    height: 58px;
    line-height: 58px;
    background: linear-gradient(
      135deg,
      rgba(42, 163, 255, 0.20000000298023224) 0%,
      rgba(43, 112, 156, 0.00009999999747378752) 100%
    );
    border-bottom: 2px solid;
    border-image: radial-gradient(
        circle,
        rgba(42.5000012665987, 162.608702480793, 255, 1),
        rgba(
          28.000000230968,
          109.00000110268593,
          171.00000500679016,
          0.4000000059604645
        ),
        rgba(
          43.00000123679638,
          112.000000923872,
          156.00000590085983,
          0.10000000149011612
        )
      )
      2 2;
  }
}
.memory-div {
  width: 100%;
  padding: 10px 40px 0px 20px;
  height: 380px;
  .left {
    float: left;
    display: inline-flex;
    width: 140px;
    flex-direction: column;
    height: 100%;
    justify-content: center;
  }
  .right {
    float: right;
    display: inline-flex;
    width: 88px;
    flex-direction: column;
    height: 100%;
    justify-content: center;
  }
}
.right-item {
  width: 88px;
  color: #fff;
  font-size: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 20px;
}
.left-item {
  list-style: none;
  margin-bottom: 20px;
  i {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
  }
  span {
    color: #fff;
    font-size: 14px;
  }
}
.clearfix:after {
  visibility: hidden;
  display: block;
  font-size: 0;
  content: ' ';
  clear: both;
  height: 0;
}
</style>
